package com.jinyu.admin.controller.sys;

import com.jinyu.admin.service.sys.SysDictDataService;
import com.jinyu.admin.service.sys.SysDictTypeService;
import com.jinyu.common.base.ApiRestResponse;
import com.jinyu.dao.entity.sys.SysDictData;
import com.jinyu.dao.entity.sys.SysDictType;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: yangli
 * @Despriction: 字典项数据模块
 * @Package: com.jinyu.admin.controller.sys
 * @Date:Created in 2022/5/6 22:36
 * @Modify By:
 */
@Slf4j
@RestController
@RequestMapping("/dict")
public class SysDictController {

    @Autowired
    private SysDictDataService sysDictDataService;

    @Autowired
    private SysDictTypeService sysDictTypeService;

    /**
     *  新增字典数据接口
     * @param sysDictData   字典数据
     * @return
     */
    @PostMapping("/addDictData/1.0")
    public ApiRestResponse<Object> addDictData (@RequestBody @Valid SysDictData sysDictData) {
        log.info("字典数据信息{}",sysDictData.toString());
        int insert = sysDictDataService.insert(sysDictData);
        return insert > 0 ? ApiRestResponse.ok("新增字典数据成功") : ApiRestResponse.err("新增字典数据失败");
    }

    /**
     *  新增字典类型接口
     * @param sysDictType   字典类型
     * @return  ApiRestResponse
     */
    @PostMapping("/addDictType/1.0")
    public ApiRestResponse<Object> addDictType (@RequestBody @Valid SysDictType sysDictType) {
        log.info("字典数据信息{}",sysDictType.toString());
        int insert = sysDictTypeService.insert(sysDictType);
        return insert > 0 ? ApiRestResponse.ok("新增字典类型成功") : ApiRestResponse.err("新增字典类型失败");
    }

}